package com.powerwyx.shortlink.project.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.powerwyx.shortlink.project.common.convention.result.Result;
import com.powerwyx.shortlink.project.common.convention.result.Results;
import com.powerwyx.shortlink.project.pojo.dto.RecycleBinRecoverDTO;
import com.powerwyx.shortlink.project.pojo.dto.RecycleBinRemoveDTO;
import com.powerwyx.shortlink.project.pojo.dto.RecycleBinSaveDTO;
import com.powerwyx.shortlink.project.pojo.dto.ShortLinkRecycleBinPageDTO;
import com.powerwyx.shortlink.project.pojo.vo.ShortLinkPageVO;
import com.powerwyx.shortlink.project.service.RecycleBinService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author 王艺锡
 * @version 1.0
 */
@Slf4j
@RestController
@RequestMapping("/api/shortlink/v1/recyclebin")
public class RecycleBinController {

    @Autowired
    private RecycleBinService recycleBinService;

    /**
     * 添加短链接至回收站
     * @param recycleBinSaveDTO
     * @return
     */
    @PostMapping("/save")
    public Result<Void> saveRecycleBin(@RequestBody RecycleBinSaveDTO recycleBinSaveDTO){
        recycleBinService.saveRecycleBin(recycleBinSaveDTO);
        return Results.success();
    }

    /**
     * 将短链接从回收站移出
     * @param recycleBinRecoverDTO
     * @return
     */
    @PostMapping("/recover")
    public Result<Void> recoverRecycleBin(@RequestBody RecycleBinRecoverDTO recycleBinRecoverDTO){
        recycleBinService.recoverRecycleBin(recycleBinRecoverDTO);
        return Results.success();
    }


    /**
     * 根据分组进行分页查询回收站中的短链接
     * @param shortLinkRecycleBinPageDTO
     * @return
     */
    @GetMapping("/page")
    public Result<IPage<ShortLinkPageVO>> shortLinkRecycleBinPage(ShortLinkRecycleBinPageDTO shortLinkRecycleBinPageDTO){
        return Results.success(recycleBinService.shortLinkRecycleBinPage(shortLinkRecycleBinPageDTO));
    }


    /**
     * 删除回收站短链接
     * @param recycleBinRemoveDTO
     * @return
     */
    @PostMapping("/remove")
    public Result<Void> removeRecycleBin(@RequestBody RecycleBinRemoveDTO recycleBinRemoveDTO){
        recycleBinService.removeRecycleBin(recycleBinRemoveDTO);
        return Results.success();
    }


}
